<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @name        Ajax controller
 * @author      PyroCMS Development Team
 * @package     PyroCMS
 * @subpackage  Controllers
 */
class Ajax extends CI_Controller {

    function url_title()
    {
        $this->load->helper('text');

        $slug = trim(url_title($this->input->post('title'), 'dash', TRUE), '-');

        $this->output->set_output($slug);
    }

    function upload() {
   
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '20000000'; //20M
            $config['overwrite'] = false;
            $this->load->library('upload', $config);

            if (!$this->upload->do_upload('imageFile')) {
                echo "error|" . $this->upload->display_errors();
            } else {
                $respond = $this->upload->data();

                $imagesize = getimagesize($respond['full_path']);
                //Make thumbnail
                $image['source_image'] = $respond['full_path'];
                $image['create_thumb'] = true;
                $image['thumb_marker'] = '';
                $image['new_image'] = './uploads/thumbs_top/' . $respond['file_name'];
                $image['width'] = 162;
                $image['height'] = 100;

		$this->load->library('image_lib', $image);
                if (!$this->image_lib->resize())
                {
                    echo 'error|' . $this->image_lib->display_errors();
                }
		
		$image['new_image'] = './uploads/thumbs_slide/' . $respond['file_name'];
		$image['width'] = 933;
                $image['height'] = 313;
		$this->image_lib->clear();
		$this->image_lib->initialize($image);
                if (!$this->image_lib->resize())
                {
                    echo 'error|' . $this->image_lib->display_errors();
                }
		
		$image['new_image'] = './uploads/thumbs_monitor/' . $respond['file_name'];
		$image['width'] = 292;
                $image['height'] = 174;
		$this->image_lib->clear();
		$this->image_lib->initialize($image);
                if (!$this->image_lib->resize())
                {
                    echo 'error|' . $this->image_lib->display_errors();
                }

		echo $respond['file_name'];
            }

    }
    function upload_video() {

            $config['upload_path'] = './uploads/video/';
            $config['allowed_types'] = 'avi|mpg|wmv|flv';
            $config['max_size'] = '500000000'; //200M
            $config['overwrite'] = true;
            $this->load->library('upload', $config);

            if (!$this->upload->do_upload('videoFile')) {
                echo "error|" . $this->upload->display_errors();
            } else {
                $respond = $this->upload->data();

                $imagesize = filesize($respond['full_path']);
                //Make thumbnail
                $image['source_video'] = $respond['full_path'];
                //$image['create_thumb'] = true;
                //$image['thumb_marker'] = '';
                //$image['new_image'] = './uploads/thumbs/' . $respond['file_name'];
                //$image['width'] = (int) (($imagesize[0] * 100) / $imagesize[1]);
                //$image['height'] = 100;
                //$this->load->library('image_lib', $image);
                //if ($this->image_lib->resize()) {
                //    echo $respond['file_name'];
                //} else {
                //    echo 'error|' . $this->image_lib->display_errors();
                //}
                echo $respond['file_name'];
            }

    }

}